<?php
	class lopdb
	{
		public function Add($TenLop,$MaKhoi)
		{
			$sql = "INSERT INTO `tbl_lop`(`TenLop`, `MaKhoi`) 
			VALUES (".dataservice::slashes($TenLop).",$MaKhoi)";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaLop)
		{
			$sql = "DELETE FROM `tbl_lop` WHERE MaLop = '$MaLop' ";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Update($MaLop,$TenLop,$MaKhoi)
		{
			$sql = "UPDATE `tbl_lop`
			 SET TenLop = ".dataservice::slashes($TenLop).",
				 MaKhoi = $MaKhoi
			 WHERE MaLop = '$MaLop'"; 
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	
	
		public function GetList($MaLop,$TenLop,$MaKhoi)
		{
			$sql = " SELECT * FROM `tbl_lop`,`tbl_khoi` WHERE tbl_lop.MaKhoi = tbl_khoi.MaKhoi ";
			if($MaLop!="")
				$sql .= " AND tbl_lop.MaLop = $MaLop ";
			if($TenLop!="")
				$sql .= " AND tbl_lop.TenLop = '$TenLop' ";
			if($MaKhoi!="")
				$sql .= " AND tbl_lop.MaKhoi = $MaKhoi ";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function GetList_Khoi($MaLop,$TenLop,$MaKhoi)
		{
			$sql = " SELECT * FROM `tbl_lop`,`tbl_khoi` WHERE tbl_lop.MaKhoi = tbl_khoi.MaKhoi ";
			if($MaLop!="")
				$sql .= " AND tbl_lop.MaLop = $MaLop ";
			if($TenLop!="")
				$sql .= " AND tbl_lop.TenLop = '$TenLop' ";
			if($MaKhoi!="")
				$sql .= " AND tbl_lop.MaKhoi = $MaKhoi ";
			$sql .= " GROUP BY tbl_lop.MaKhoi ";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function Find($MaLop,$TenLop,$MaKhoi)
		{
			$sql = " SELECT * FROM `tbl_lop`,`tbl_khoi` WHERE tbl_lop.MaKhoi = tbl_khoi.MaKhoi ";
			if($MaLop!="")
				$sql .= " AND tbl_lop.MaLop = $MaLop ";
			if($TenLop!="")
				$sql .= " AND tbl_lop.TenLop LIKE '%$TenLop%' ";
			if($MaKhoi!="")
				$sql .= " AND tbl_lop.MaKhoi = $MaKhoi ";	
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
	}
?>